package com.neusoft.productsys.controller;

import com.neusoft.productsys.entity.UserInfo;
import com.neusoft.productsys.service.LoginServie;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/login.do")
public class LoginServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

          req.setCharacterEncoding("UTF-8");
          String uname = req.getParameter("uname");
          String pwd = req.getParameter("pwd");
          LoginServie servie = new LoginServie();
          UserInfo userInfo = servie.Login(uname,pwd);

          if(null!=userInfo)
          {
              req.getSession().setAttribute("user",userInfo);
              req.getRequestDispatcher("showp.do").forward(req,resp);
          }else
          {
              req.getRequestDispatcher("index.jsp").forward(req,resp);
          }

    }
}
